package com.hzsai.config;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.thymeleaf.exceptions.TemplateInputException;

import java.util.HashMap;
import java.util.Map;

/**
 * hzsai 2019/8/13
 * usage:
 **/
@ControllerAdvice
public class MyControllerAdvice {

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Map errorHandler(Exception ex) {
        Map<String, Object> ret = new HashMap<>();
        ret.put("code", 400);
        ret.put("msg", ex.getMessage());
        return ret;
    }

//    @ResponseBody
//    @ExceptionHandler(MyNullPtrException.class)
//    public Map myNulPtrExceptionHandler(MyNullPtrException ex) {
//        Map<String, Object> ret = new HashMap<>();
//        ret.put("code", 400);
//        ret.put("msg", ex.getMessage());
//        return ret;
//    }
}
